import { config } from '../../config/index';
import { post } from '../../utils/request';

/** 获取商品列表 */
function mockFetchGood(ID = 0) {
  console.log(ID)
  const { delay } = require('../_utils/delay');
  const { genGood } = require('../../model/good');
  return delay().then(() => genGood(ID));
}

/** 获取商品列表 */
export function fetchGood(ID = 0) {
  if (config.useMock) {
    return mockFetchGood(ID);
  }
  return new Promise((resolve, reject) => {
    post('/home/goods/getGoodsDetail', { spuId: ID }).then(res => {
      resolve(res.data);
    }).catch(err => {
      reject(err);
    });
  });
}
